package com.longdaji.decoration.ui.activitiesOfMine.balance;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.adapter.BalanceAdapter;
import com.longdaji.decoration.base.BaseActivity;
import com.longdaji.decoration.bean.Balance;
import com.longdaji.decoration.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BalanceActivity extends BaseActivity implements BalanceContract.IView {

    @Inject
    BalanceContract.IPresenter mPresenter;

    @BindView(R.id.tv_tool_title)
    TextView tvTitle;
    @BindView(R.id.rv_balance_detail)
    RecyclerView rvBalanceDetail;
    @BindView(R.id.tv_balance)
    TextView tvBalance;

    private BalanceAdapter mAdapter;
    private List<Balance.RecordsBean> mBalanceRecordList = new ArrayList<>();

    private int type = -1;
    private int pageNo = 1;
    private int pageSize = 20;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_balance);

        setUnBinder(ButterKnife.bind(this));

        if (mPresenter != null)
            mPresenter.setView(this);
        tvTitle.setText("我的余额");

        initView();
    }

    private void initView() {
        final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        rvBalanceDetail.setLayoutManager(layoutManager);
        mAdapter = new BalanceAdapter(mBalanceRecordList);
        rvBalanceDetail.setAdapter(mAdapter);

//        rvBalanceDetail.addOnScrollListener(new RecyclerView.OnScrollListener() {
//            @Override
//            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
//                super.onScrollStateChanged(recyclerView, newState);
//            }
//        });

        mPresenter.doInitData(type, pageNo, pageSize);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter != null)
            mPresenter.detachView();
    }


    @OnClick({R.id.rl_tool_back})
    void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_tool_back:
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    public void showInitBalanceDetail(Balance balance) {
        tvBalance.setText(balance.getTotalBalance());
        mAdapter.setData(balance.getRecords());
    }
}
